CC = gcc

CFLAGS = -Wall -Wextra

INCLUDE = -I.
INCLUDE += -Ithirdparty/cjson
INCLUDE += -Ithirdparty/log
INCLUDE += -Iapp/common
INCLUDE += -Iapp/message
INCLUDE += -Iapp/thread_pool
INCLUDE += -Iapp/mqtt_client
INCLUDE += -Iapp/router
INCLUDE += -Iapp/serial
INCLUDE += -Iapp/bluetooth
INCLUDE += -Iapp/device

LIBRARY = -lpaho-mqtt3c

SRC += $(shell find app -name "*.c" -type f)
SRC += $(shell find thirdparty -name "*.c" -type f)

OBJ = $(SRC:.c=.o)

%.o:%.c
	@-$(CC) -c $^ -o $@ $(CFLAGS) $(INCLUDE) $(LIBRARY)

test_%:test/test_%.c $(OBJ)
	@-$(CC) $^ -o test/$@ $(CFLAGS) $(INCLUDE) $(LIBRARY)
	@-test/$@
	@-rm -f test/$@ $(OBJ)